//
// Created by wxd on 2025/8/19.
//

#include "LightSphere.h"

void LightSphere::setShader(const std::string &vertexPath, const std::string &fragmentPath) {
    m_Shader = std::make_unique<Shader>(vertexPath, fragmentPath);
}

void LightSphere::setHideLightSource(bool isHideLightSource) {
    m_IsHideLightSource = isHideLightSource;
}


Shader &LightSphere::getShader() const {
    return *m_Shader;
}

Sphere &LightSphere::getSphere() const {
    return *m_Sphere;
}

glm::vec3 LightSphere::getCenter() const {
    return m_Center;
}

glm::vec3 LightSphere::getColor() const {
    return m_Color;
}

void LightSphere::draw(const glm::mat4 &model, const glm::mat4 &view, const glm::mat4 &proj) {
    if (!m_IsHideLightSource) {
        m_Shader->bindProgram();
        m_Shader->setUniform("uModel", model);
        m_Shader->setUniform("uView", view);
        m_Shader->setUniform("uProj", proj);
        m_Sphere->getVAO()->bind();
        m_Sphere->draw();
        m_Sphere->getVAO()->unbind();
        m_Shader->unbindProgram();
    }
}

void LightSphere::destroy() const {
    m_Sphere->getEBO()->destroy();
    m_Sphere->getVAO()->destroy();
    m_Shader->deleteProgram();
}